var xmlHttp;

 function createXMLHttp() {
	 if (window.ActiveXObject) {
		 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	 } else {
		 xmlHttp = new XMLHttpRequest();
	 }
 }

 function ajaxSend() {
	 createXMLHttp();
	 var content = "status";
	 var url = "upload?status=" + content;
	 xmlHttp.onreadystatechange = handler;
	 xmlHttp.open("POST", url, true);
	 xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 xmlHttp.send(url);
 }
 function handler() {
	 if (xmlHttp.readyState == 4) {
		 if (xmlHttp.status == 200) {
			 var percent = xmlHttp.responseText;
			 $("#uploadProgressbar").progressbar("option","value",percent);
			 if (percent < 99) {
				 $("#uploadProgressbarStatus").html(percent+"%");
				 setTimeout("ajaxSend()", 100);
			 } else {		
				 $("#uploadProgressbar").progressbar("option","value",100);
				 $("#uploadProgressbarStatus").html("Completed");
			 }
		 }
	 }
	 return true;
 }

 function uploadSubmit(form) {
	 $("#uploadProgressbar").progressbar("option","value",0);
	 $("#uploadProgressbarStatus").html("0%");
	 form.action = "upload";
	 if(!uploadCheck(form)) return;
	 form.submit();
	 ajaxSend();
 }
 
 function uploadCheck(form) {
	 var filepath= $("#fileUpload").val();
     var extStart=filepath.lastIndexOf(".");
     var ext=filepath.substring(extStart,filepath.length).toUpperCase();
     if(ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
     alert("Only png,gif,jpeg,jpg format");
     return false;
     }


	return true;       
 }